package com.xioaye.cs.basic;
//
//
//题目描述
//        给定大小为n的整数集合A，代表n根木棍的长度。从A中任选4根木棍组成一个四边形，求其面积最大为多少。数据保证有解。
//        程序返回结果与正确答案的误差应小于0.00001

import java.util.Arrays;

public class MaxArea {

    public static void main(String[] args) {



        int[] a ={1,2,3,4,5};


        double solve = solve(a);

        System.out.println(solve);


    }



    public static double solve (int[] a) {
        // write code here
        //z = (a+b+c+d)/2;
        //ans = 根号下(z-a)*(z-b)*(z-c)*(z-d)

        Arrays.sort(a);
        int len = a.length;

        double ret = 0;

        for(int i = len;i>=4;i--){
            int a0 = a[i-1];
            int b = a[i-2];
            int c = a[i-3];
            int d = a[i-4];
            if(a0<b+c+d){
                double z = (a0+b+c+d)/2.0;
                double ans = Math.sqrt((z-a0)*(z-b)*(z-c)*(z-d));
                ret = Math.max(ans,ret);
            }else{
                continue;
            }
        }
        return ret;
    }
}
